<?php
Yii::app()->clientScript->registerCoreScript('jquery.ui');
Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
$format = Yii::app()->format;

$this->breadcrumbs = array(
	'Measurements'=>array('index'),
	'Periodic Report',
);

$this->menu = array(
	array('label'=>'Create Measurement', 'url'=>array('create')),
	array('label'=>'Manage Measurement', 'url'=>array('admin')),
);

$script = "
$('.search-form form').submit(function() {
	$.fn.yiiGridView.update('measurement-grid', {
		data: $(this).serialize()
	});
	return false;
});
";
Yii::app()->clientScript->registerScript('search', $script);
?>

<h1>Measurement Periodic Report</h1>

<div class="search-form">

	<?php
	$properties = array(
		'action'=>Yii::app()->createUrl($this->route),
		'method'=>'get',
		'type'=>'horizontal',
	);
	$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', $properties);

	$htmlOptions = array('class'=>'span5');
	echo $form->textFieldRow($model, 'deviceSequence', $htmlOptions);
	?>

	<div class="control-group ">
		<?php
		$htmlOptions = array('class'=>'control-label');
		echo $form->labelEx($model, 'firstDateTime', $htmlOptions);
		$properties = array(
			'model'=>$model,
			'attribute'=>'firstDateTime',
			'mode'=>'datetime',
			'options'=>array(
				'showSecond'=>true,
				'timeFormat'=>'hh:mm:ss',
				'dateFormat'=>'yy-mm-dd',
			),
			'language' => '',
		);
		?>
		<div class="controls">
			<?php $this->widget('CJuiDateTimePicker', $properties); ?>
		</div>
	</div>
	
	<div class="control-group ">
		<?php
		echo $form->labelEx($model, 'lastDateTime', $htmlOptions);
		$properties = array(
			'model'=>$model,
			'attribute'=>'lastDateTime',
			'mode'=>'datetime',
			'options'=>array(
				'showSecond'=>true,
				'timeFormat'=>'hh:mm:ss',
				'dateFormat'=>'yy-mm-dd',
			),
			'language' => '',
		);
		?>
		<div class="controls">
			<?php $this->widget('CJuiDateTimePicker', $properties); ?>
		</div>
	</div>
	
	<div class="form-actions">
		<?php
		$properties = array(
			'buttonType'=>'submit',
			'type'=>'primary',
			'label'=>'Search',
		);
		$this->widget('bootstrap.widgets.TbButton', $properties);
		?>
	</div>

	<?php $this->endWidget(); ?>

</div>

<?php
$properties = array(
	'id'=>'measurement-grid',
	'dataProvider'=>$model->search(),
	'filter'=>null,
	'columns'=>array(
		'createdAt:datetime',
		array(
			'headerHtmlOptions'=>array(
				'class'=>'center',
			),
			'htmlOptions'=>array(
				'class'=>'center',
			),
			'name'=>'deviceSequence',
		),
	),
);
for ($i = 1; $i <= 8; $i++) {
	$properties['columns'][] = array(
		'headerHtmlOptions'=>array(
			'class'=>'rjust',
		),
		'htmlOptions'=>array(
			'class'=>'rjust',
		),
		'header'=>$i,
		'value'=>"\$data->arrayChannels[$i]['cute']",
	);
}

$this->widget('bootstrap.widgets.TbGridView', $properties);
?>
